public class Main {
    public static boolean contains(String str, String sub) {
        if(str.length() < sub.length()) {
            //如果要查找的子字符串长度比字符串还长，那么肯定找不到
            return false;
        }
        for(int i = 0; i <= str.length()-sub.length(); i++) {
            if(str.substring(i,i+sub.length()).equals(sub)) {
                return true;
            }
        }
        return false;
    }

    public static int myIndexOf(String str, String index) {
        if(str.length() < index.length()) {
            //如果要查找的子字符串长度比字符串还长，那么肯定找不到
            return -1;
        }
        for(int i = 0; i <= str.length()-index.length(); i++) {
            if(str.substring(i,i+index.length()).equals(index)) {
                return i;
            }
        }
        return -1;
    }
    public static int myCompareTo(String a, String b) {
        int i = a.length()-1;
        int j = b.length()-1;
        while(i>=0 || j>=0) {
            int x = i>=0?a.charAt(i)-'0':0;
            int y = j>=0?b.charAt(j)-'0':0;
            if(x!=y || i==0 && j==0) {
                return x-y;
            }
            i--;
            j--;
        }
        return -404;
    }
    public static void main(String[] args) {
//        System.out.println("Hello world!");
//        实现方法 indexOf, 能够找出字符串子串存在的位置
//        System.out.println(myIndexOf(str, "d"));
//        String str = new String("hello world");
//        System.out.println(contains(str, "hello"));

        //实现方法 compareTo, 能够实现按照字典序比较字符串大小
        System.out.println(myCompareTo("abc", "abcd"));
    }
}